package org.jivesoftware.smackx.muc;

import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.PacketExtensionFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Message.Type;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;

class PacketMultiplexListener
  implements PacketListener
{
  private static final PacketFilter DECLINES_FILTER;
  private static final PacketFilter MESSAGE_FILTER = new MessageTypeFilter(Message.Type.groupchat);
  private static final PacketFilter PRESENCE_FILTER = new PacketTypeFilter(Presence.class);
  private static final PacketFilter SUBJECT_FILTER = new PacketFilter()
  {
    public boolean accept()
    {
      int i;
      if (((Message)paramPacket).getSubject() != null)
        i = 1;
      while (true)
      {
        return i;
        i = 0;
      }
    }
  };
  private PacketListener declinesListener;
  private ConnectionDetachedPacketCollector messageCollector;
  private PacketListener presenceListener;
  private PacketListener subjectListener;

  static
  {
    DECLINES_FILTER = new PacketExtensionFilter("x", "http://jabber.org/protocol/muc#user");
  }

  public PacketMultiplexListener(ConnectionDetachedPacketCollector paramConnectionDetachedPacketCollector, PacketListener paramPacketListener1, PacketListener paramPacketListener2, PacketListener paramPacketListener3)
  {
    if (paramConnectionDetachedPacketCollector == null)
      throw new IllegalArgumentException("MessageCollector is null");
    if (paramPacketListener1 == null)
      throw new IllegalArgumentException("Presence listener is null");
    if (paramPacketListener2 == null)
      throw new IllegalArgumentException("Subject listener is null");
    if (paramPacketListener3 == null)
      throw new IllegalArgumentException("Declines listener is null");
    this.messageCollector = paramConnectionDetachedPacketCollector;
    this.presenceListener = paramPacketListener1;
    this.subjectListener = paramPacketListener2;
    this.declinesListener = paramPacketListener3;
  }

  public void processPacket(Packet paramPacket)
  {
    if (PRESENCE_FILTER.accept(paramPacket))
      this.presenceListener.processPacket(paramPacket);
    while (true)
    {
      label68: 
      do
        while (true)
        {
          do
          {
            return;
            if (!(MESSAGE_FILTER.accept(paramPacket)))
              break label68;
            this.messageCollector.processPacket(paramPacket);
          }
          while (!(SUBJECT_FILTER.accept(paramPacket)));
          this.subjectListener.processPacket(paramPacket);
        }
      while (!(DECLINES_FILTER.accept(paramPacket)));
      this.declinesListener.processPacket(paramPacket);
    }
  }
}